# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("//llvm:lit_test.bzl", "lit_test", "package_path")

expand_template(
    name = "lit_site_cfg",
    testonly = True,
    out = "lit.site.cfg",
    substitutions = {
        "@LIT_SITE_CFG_IN_HEADER@": "# Autogenerated, do not edit.",
        "@LLVM_LIT_TOOLS_DIR@": package_path("//llvm/utils/lit:BUILD"),
        "@LLVM_SOURCE_DIR@": package_path("//llvm:BUILD"),
        "@LLVM_BINARY_DIR@": package_path("//llvm:BUILD"),
        "@LLVM_TOOLS_DIR@": package_path("//llvm:BUILD"),
    },
    template = "lit.site.cfg.in",
)

[
    lit_test(
        name = "%s.test" % src,
        srcs = [src],
        args = ["--path %s" % package_path("//llvm:BUILD")],
        data = [
            "lit.cfg",
            "lit.site.cfg",
            "check-tested-lit-timeout-ability",
            "//llvm:FileCheck",
            "//llvm:count",
            "//llvm:not",
        ] + glob(["Inputs/**"]),
    )
    for src in glob(["*/*.py"])
]
